{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import tushare as ts"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "df = ts.get_sina_dd('123006',date='2019-04-03',vol=100)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "ename": "AttributeError",
     "evalue": "'NoneType' object has no attribute 'head'",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mAttributeError\u001b[0m                            Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-11-c42a15b2c7cf>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mdf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mhead\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;31mAttributeError\u001b[0m: 'NoneType' object has no attribute 'head'"
     ]
    }
   ],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[Getting data:]#Error reading file 'http://vip.stock.finance.sina.com.cn/quotes_service/view/vMS_tradedetail.php?symbol=sz123006&date=2019-04-04&page=1': failed to load HTTP resource\n",
      "Error reading file 'http://vip.stock.finance.sina.com.cn/quotes_service/view/vMS_tradedetail.php?symbol=sz123006&date=2019-04-04&page=1': failed to load HTTP resource\n",
      "Error reading file 'http://vip.stock.finance.sina.com.cn/quotes_service/view/vMS_tradedetail.php?symbol=sz123006&date=2019-04-04&page=1': failed to load HTTP resource\n",
      "获取失败，请检查网络.\n",
      "HTTP Error 456: \n",
      "HTTP Error 456: \n"
     ]
    },
    {
     "ename": "OSError",
     "evalue": "获取失败，请检查网络.",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mOSError\u001b[0m                                   Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-8-117d9b17bc59>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mdf\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mts\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget_today_ticks\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'123006'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\tushare\\stock\\trading.py\u001b[0m in \u001b[0;36mget_today_ticks\u001b[1;34m(code, retry_count, pause)\u001b[0m\n\u001b[0;32m    273\u001b[0m         \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    274\u001b[0m             \u001b[1;32mreturn\u001b[0m \u001b[0mdata\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 275\u001b[1;33m     \u001b[1;32mraise\u001b[0m \u001b[0mIOError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mct\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mNETWORK_URL_ERROR_MSG\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    276\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    277\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mOSError\u001b[0m: 获取失败，请检查网络."
     ]
    }
   ],
   "source": [
    "df = ts.get_today_ticks('123006')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\ProgramData\\Anaconda3\\lib\\site-packages\\tushare\\stock\\trading.py:182: FutureWarning: read_table is deprecated, use read_csv instead, passing sep='\\t'.\n",
      "  skiprows=[0])\n"
     ]
    }
   ],
   "source": [
    "df=ts.get_tick_data('123006',date='2019-04-03',src='tt')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>time</th>\n",
       "      <th>price</th>\n",
       "      <th>change</th>\n",
       "      <th>volume</th>\n",
       "      <th>amount</th>\n",
       "      <th>type</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>09:25:04</td>\n",
       "      <td>178.00</td>\n",
       "      <td>-0.75</td>\n",
       "      <td>294</td>\n",
       "      <td>523323</td>\n",
       "      <td>卖盘</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>09:30:03</td>\n",
       "      <td>178.00</td>\n",
       "      <td>-0.00</td>\n",
       "      <td>142</td>\n",
       "      <td>252767</td>\n",
       "      <td>卖盘</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>09:30:06</td>\n",
       "      <td>177.50</td>\n",
       "      <td>-0.50</td>\n",
       "      <td>1180</td>\n",
       "      <td>2098086</td>\n",
       "      <td>卖盘</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>09:30:09</td>\n",
       "      <td>177.50</td>\n",
       "      <td>0.00</td>\n",
       "      <td>69</td>\n",
       "      <td>122406</td>\n",
       "      <td>买盘</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>09:30:12</td>\n",
       "      <td>177.61</td>\n",
       "      <td>0.11</td>\n",
       "      <td>610</td>\n",
       "      <td>1082802</td>\n",
       "      <td>买盘</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       time   price  change  volume   amount type\n",
       "0  09:25:04  178.00   -0.75     294   523323   卖盘\n",
       "1  09:30:03  178.00   -0.00     142   252767   卖盘\n",
       "2  09:30:06  177.50   -0.50    1180  2098086   卖盘\n",
       "3  09:30:09  177.50    0.00      69   122406   买盘\n",
       "4  09:30:12  177.61    0.11     610  1082802   买盘"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 4481 entries, 0 to 4480\n",
      "Data columns (total 6 columns):\n",
      "time      4481 non-null object\n",
      "price     4481 non-null float64\n",
      "change    4481 non-null float64\n",
      "volume    4481 non-null int64\n",
      "amount    4481 non-null int64\n",
      "type      4481 non-null object\n",
      "dtypes: float64(2), int64(2), object(2)\n",
      "memory usage: 210.1+ KB\n"
     ]
    }
   ],
   "source": [
    "df.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "df['time']=pd.to_datetime(df['time'],format='%Y-%m-%d %H:%M:%S')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>time</th>\n",
       "      <th>price</th>\n",
       "      <th>change</th>\n",
       "      <th>volume</th>\n",
       "      <th>amount</th>\n",
       "      <th>type</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2019-04-04 09:25:04</td>\n",
       "      <td>178.00</td>\n",
       "      <td>-0.75</td>\n",
       "      <td>294</td>\n",
       "      <td>523323</td>\n",
       "      <td>卖盘</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2019-04-04 09:30:03</td>\n",
       "      <td>178.00</td>\n",
       "      <td>-0.00</td>\n",
       "      <td>142</td>\n",
       "      <td>252767</td>\n",
       "      <td>卖盘</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2019-04-04 09:30:06</td>\n",
       "      <td>177.50</td>\n",
       "      <td>-0.50</td>\n",
       "      <td>1180</td>\n",
       "      <td>2098086</td>\n",
       "      <td>卖盘</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2019-04-04 09:30:09</td>\n",
       "      <td>177.50</td>\n",
       "      <td>0.00</td>\n",
       "      <td>69</td>\n",
       "      <td>122406</td>\n",
       "      <td>买盘</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2019-04-04 09:30:12</td>\n",
       "      <td>177.61</td>\n",
       "      <td>0.11</td>\n",
       "      <td>610</td>\n",
       "      <td>1082802</td>\n",
       "      <td>买盘</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                 time   price  change  volume   amount type\n",
       "0 2019-04-04 09:25:04  178.00   -0.75     294   523323   卖盘\n",
       "1 2019-04-04 09:30:03  178.00   -0.00     142   252767   卖盘\n",
       "2 2019-04-04 09:30:06  177.50   -0.50    1180  2098086   卖盘\n",
       "3 2019-04-04 09:30:09  177.50    0.00      69   122406   买盘\n",
       "4 2019-04-04 09:30:12  177.61    0.11     610  1082802   买盘"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "import datetime"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "today = datetime.date.today().strftime('%Y-%m-%d')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "df['time']=df['time'].map(lambda x:today+' '+x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>time</th>\n",
       "      <th>price</th>\n",
       "      <th>change</th>\n",
       "      <th>volume</th>\n",
       "      <th>amount</th>\n",
       "      <th>type</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2019-04-04 09:25:04</td>\n",
       "      <td>178.00</td>\n",
       "      <td>-0.75</td>\n",
       "      <td>294</td>\n",
       "      <td>523323</td>\n",
       "      <td>卖盘</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2019-04-04 09:30:03</td>\n",
       "      <td>178.00</td>\n",
       "      <td>-0.00</td>\n",
       "      <td>142</td>\n",
       "      <td>252767</td>\n",
       "      <td>卖盘</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2019-04-04 09:30:06</td>\n",
       "      <td>177.50</td>\n",
       "      <td>-0.50</td>\n",
       "      <td>1180</td>\n",
       "      <td>2098086</td>\n",
       "      <td>卖盘</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2019-04-04 09:30:09</td>\n",
       "      <td>177.50</td>\n",
       "      <td>0.00</td>\n",
       "      <td>69</td>\n",
       "      <td>122406</td>\n",
       "      <td>买盘</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2019-04-04 09:30:12</td>\n",
       "      <td>177.61</td>\n",
       "      <td>0.11</td>\n",
       "      <td>610</td>\n",
       "      <td>1082802</td>\n",
       "      <td>买盘</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                  time   price  change  volume   amount type\n",
       "0  2019-04-04 09:25:04  178.00   -0.75     294   523323   卖盘\n",
       "1  2019-04-04 09:30:03  178.00   -0.00     142   252767   卖盘\n",
       "2  2019-04-04 09:30:06  177.50   -0.50    1180  2098086   卖盘\n",
       "3  2019-04-04 09:30:09  177.50    0.00      69   122406   买盘\n",
       "4  2019-04-04 09:30:12  177.61    0.11     610  1082802   买盘"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>time</th>\n",
       "      <th>price</th>\n",
       "      <th>change</th>\n",
       "      <th>volume</th>\n",
       "      <th>amount</th>\n",
       "      <th>type</th>\n",
       "      <th>times</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2019-04-03 09:25:04</td>\n",
       "      <td>178.00</td>\n",
       "      <td>-0.75</td>\n",
       "      <td>294</td>\n",
       "      <td>523323</td>\n",
       "      <td>卖盘</td>\n",
       "      <td>1900-01-01 09:25:04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2019-04-03 09:30:03</td>\n",
       "      <td>178.00</td>\n",
       "      <td>-0.00</td>\n",
       "      <td>142</td>\n",
       "      <td>252767</td>\n",
       "      <td>卖盘</td>\n",
       "      <td>1900-01-01 09:30:03</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2019-04-03 09:30:06</td>\n",
       "      <td>177.50</td>\n",
       "      <td>-0.50</td>\n",
       "      <td>1180</td>\n",
       "      <td>2098086</td>\n",
       "      <td>卖盘</td>\n",
       "      <td>1900-01-01 09:30:06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2019-04-03 09:30:09</td>\n",
       "      <td>177.50</td>\n",
       "      <td>0.00</td>\n",
       "      <td>69</td>\n",
       "      <td>122406</td>\n",
       "      <td>买盘</td>\n",
       "      <td>1900-01-01 09:30:09</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2019-04-03 09:30:12</td>\n",
       "      <td>177.61</td>\n",
       "      <td>0.11</td>\n",
       "      <td>610</td>\n",
       "      <td>1082802</td>\n",
       "      <td>买盘</td>\n",
       "      <td>1900-01-01 09:30:12</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                  time   price  change  volume   amount type  \\\n",
       "0  2019-04-03 09:25:04  178.00   -0.75     294   523323   卖盘   \n",
       "1  2019-04-03 09:30:03  178.00   -0.00     142   252767   卖盘   \n",
       "2  2019-04-03 09:30:06  177.50   -0.50    1180  2098086   卖盘   \n",
       "3  2019-04-03 09:30:09  177.50    0.00      69   122406   买盘   \n",
       "4  2019-04-03 09:30:12  177.61    0.11     610  1082802   买盘   \n",
       "\n",
       "                times  \n",
       "0 1900-01-01 09:25:04  \n",
       "1 1900-01-01 09:30:03  \n",
       "2 1900-01-01 09:30:06  \n",
       "3 1900-01-01 09:30:09  \n",
       "4 1900-01-01 09:30:12  "
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "del df['times']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>time</th>\n",
       "      <th>price</th>\n",
       "      <th>change</th>\n",
       "      <th>volume</th>\n",
       "      <th>amount</th>\n",
       "      <th>type</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2019-04-03 09:25:04</td>\n",
       "      <td>178.00</td>\n",
       "      <td>-0.75</td>\n",
       "      <td>294</td>\n",
       "      <td>523323</td>\n",
       "      <td>卖盘</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2019-04-03 09:30:03</td>\n",
       "      <td>178.00</td>\n",
       "      <td>-0.00</td>\n",
       "      <td>142</td>\n",
       "      <td>252767</td>\n",
       "      <td>卖盘</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2019-04-03 09:30:06</td>\n",
       "      <td>177.50</td>\n",
       "      <td>-0.50</td>\n",
       "      <td>1180</td>\n",
       "      <td>2098086</td>\n",
       "      <td>卖盘</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2019-04-03 09:30:09</td>\n",
       "      <td>177.50</td>\n",
       "      <td>0.00</td>\n",
       "      <td>69</td>\n",
       "      <td>122406</td>\n",
       "      <td>买盘</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2019-04-03 09:30:12</td>\n",
       "      <td>177.61</td>\n",
       "      <td>0.11</td>\n",
       "      <td>610</td>\n",
       "      <td>1082802</td>\n",
       "      <td>买盘</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                  time   price  change  volume   amount type\n",
       "0  2019-04-03 09:25:04  178.00   -0.75     294   523323   卖盘\n",
       "1  2019-04-03 09:30:03  178.00   -0.00     142   252767   卖盘\n",
       "2  2019-04-03 09:30:06  177.50   -0.50    1180  2098086   卖盘\n",
       "3  2019-04-03 09:30:09  177.50    0.00      69   122406   买盘\n",
       "4  2019-04-03 09:30:12  177.61    0.11     610  1082802   买盘"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [],
   "source": [
    "df = df.set_index('time',drop=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>price</th>\n",
       "      <th>change</th>\n",
       "      <th>volume</th>\n",
       "      <th>amount</th>\n",
       "      <th>type</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>time</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-04-03 09:25:04</th>\n",
       "      <td>178.00</td>\n",
       "      <td>-0.75</td>\n",
       "      <td>294</td>\n",
       "      <td>523323</td>\n",
       "      <td>卖盘</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-04-03 09:30:03</th>\n",
       "      <td>178.00</td>\n",
       "      <td>-0.00</td>\n",
       "      <td>142</td>\n",
       "      <td>252767</td>\n",
       "      <td>卖盘</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-04-03 09:30:06</th>\n",
       "      <td>177.50</td>\n",
       "      <td>-0.50</td>\n",
       "      <td>1180</td>\n",
       "      <td>2098086</td>\n",
       "      <td>卖盘</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-04-03 09:30:09</th>\n",
       "      <td>177.50</td>\n",
       "      <td>0.00</td>\n",
       "      <td>69</td>\n",
       "      <td>122406</td>\n",
       "      <td>买盘</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-04-03 09:30:12</th>\n",
       "      <td>177.61</td>\n",
       "      <td>0.11</td>\n",
       "      <td>610</td>\n",
       "      <td>1082802</td>\n",
       "      <td>买盘</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                      price  change  volume   amount type\n",
       "time                                                     \n",
       "2019-04-03 09:25:04  178.00   -0.75     294   523323   卖盘\n",
       "2019-04-03 09:30:03  178.00   -0.00     142   252767   卖盘\n",
       "2019-04-03 09:30:06  177.50   -0.50    1180  2098086   卖盘\n",
       "2019-04-03 09:30:09  177.50    0.00      69   122406   买盘\n",
       "2019-04-03 09:30:12  177.61    0.11     610  1082802   买盘"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>price</th>\n",
       "      <th>change</th>\n",
       "      <th>volume</th>\n",
       "      <th>amount</th>\n",
       "      <th>type</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>time</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-04-03 09:30:03</th>\n",
       "      <td>178.00</td>\n",
       "      <td>-0.00</td>\n",
       "      <td>142</td>\n",
       "      <td>252767</td>\n",
       "      <td>卖盘</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-04-03 09:30:06</th>\n",
       "      <td>177.50</td>\n",
       "      <td>-0.50</td>\n",
       "      <td>1180</td>\n",
       "      <td>2098086</td>\n",
       "      <td>卖盘</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-04-03 09:30:09</th>\n",
       "      <td>177.50</td>\n",
       "      <td>0.00</td>\n",
       "      <td>69</td>\n",
       "      <td>122406</td>\n",
       "      <td>买盘</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-04-03 09:30:12</th>\n",
       "      <td>177.61</td>\n",
       "      <td>0.11</td>\n",
       "      <td>610</td>\n",
       "      <td>1082802</td>\n",
       "      <td>买盘</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-04-03 09:30:15</th>\n",
       "      <td>177.93</td>\n",
       "      <td>0.32</td>\n",
       "      <td>9</td>\n",
       "      <td>16014</td>\n",
       "      <td>中性盘</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-04-03 09:30:21</th>\n",
       "      <td>177.78</td>\n",
       "      <td>-0.15</td>\n",
       "      <td>388</td>\n",
       "      <td>689325</td>\n",
       "      <td>买盘</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-04-03 09:30:24</th>\n",
       "      <td>177.60</td>\n",
       "      <td>-0.18</td>\n",
       "      <td>353</td>\n",
       "      <td>627006</td>\n",
       "      <td>卖盘</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-04-03 09:30:27</th>\n",
       "      <td>177.80</td>\n",
       "      <td>0.20</td>\n",
       "      <td>1</td>\n",
       "      <td>1778</td>\n",
       "      <td>中性盘</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-04-03 09:30:30</th>\n",
       "      <td>177.80</td>\n",
       "      <td>0.00</td>\n",
       "      <td>6</td>\n",
       "      <td>10668</td>\n",
       "      <td>中性盘</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-04-03 09:30:33</th>\n",
       "      <td>177.50</td>\n",
       "      <td>-0.30</td>\n",
       "      <td>510</td>\n",
       "      <td>906119</td>\n",
       "      <td>卖盘</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-04-03 09:30:36</th>\n",
       "      <td>177.51</td>\n",
       "      <td>0.01</td>\n",
       "      <td>92</td>\n",
       "      <td>163370</td>\n",
       "      <td>买盘</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-04-03 09:30:39</th>\n",
       "      <td>177.88</td>\n",
       "      <td>0.37</td>\n",
       "      <td>40</td>\n",
       "      <td>71152</td>\n",
       "      <td>买盘</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-04-03 09:30:42</th>\n",
       "      <td>177.70</td>\n",
       "      <td>-0.18</td>\n",
       "      <td>61</td>\n",
       "      <td>108397</td>\n",
       "      <td>买盘</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-04-03 09:30:45</th>\n",
       "      <td>177.20</td>\n",
       "      <td>-0.50</td>\n",
       "      <td>502</td>\n",
       "      <td>890876</td>\n",
       "      <td>卖盘</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-04-03 09:30:48</th>\n",
       "      <td>177.00</td>\n",
       "      <td>-0.20</td>\n",
       "      <td>500</td>\n",
       "      <td>886344</td>\n",
       "      <td>卖盘</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-04-03 09:30:51</th>\n",
       "      <td>177.52</td>\n",
       "      <td>0.52</td>\n",
       "      <td>5</td>\n",
       "      <td>8876</td>\n",
       "      <td>中性盘</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-04-03 09:30:54</th>\n",
       "      <td>177.31</td>\n",
       "      <td>-0.21</td>\n",
       "      <td>101</td>\n",
       "      <td>179253</td>\n",
       "      <td>中性盘</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-04-03 09:30:57</th>\n",
       "      <td>177.48</td>\n",
       "      <td>0.17</td>\n",
       "      <td>1</td>\n",
       "      <td>1775</td>\n",
       "      <td>买盘</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                      price  change  volume   amount type\n",
       "time                                                     \n",
       "2019-04-03 09:30:03  178.00   -0.00     142   252767   卖盘\n",
       "2019-04-03 09:30:06  177.50   -0.50    1180  2098086   卖盘\n",
       "2019-04-03 09:30:09  177.50    0.00      69   122406   买盘\n",
       "2019-04-03 09:30:12  177.61    0.11     610  1082802   买盘\n",
       "2019-04-03 09:30:15  177.93    0.32       9    16014  中性盘\n",
       "2019-04-03 09:30:21  177.78   -0.15     388   689325   买盘\n",
       "2019-04-03 09:30:24  177.60   -0.18     353   627006   卖盘\n",
       "2019-04-03 09:30:27  177.80    0.20       1     1778  中性盘\n",
       "2019-04-03 09:30:30  177.80    0.00       6    10668  中性盘\n",
       "2019-04-03 09:30:33  177.50   -0.30     510   906119   卖盘\n",
       "2019-04-03 09:30:36  177.51    0.01      92   163370   买盘\n",
       "2019-04-03 09:30:39  177.88    0.37      40    71152   买盘\n",
       "2019-04-03 09:30:42  177.70   -0.18      61   108397   买盘\n",
       "2019-04-03 09:30:45  177.20   -0.50     502   890876   卖盘\n",
       "2019-04-03 09:30:48  177.00   -0.20     500   886344   卖盘\n",
       "2019-04-03 09:30:51  177.52    0.52       5     8876  中性盘\n",
       "2019-04-03 09:30:54  177.31   -0.21     101   179253  中性盘\n",
       "2019-04-03 09:30:57  177.48    0.17       1     1775   买盘"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['2019-04-03 09:30']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "DatetimeIndex: 4481 entries, 2019-04-03 09:25:04 to 2019-04-03 15:00:04\n",
      "Data columns (total 5 columns):\n",
      "price     4481 non-null float64\n",
      "change    4481 non-null float64\n",
      "volume    4481 non-null int64\n",
      "amount    4481 non-null int64\n",
      "type      4481 non-null object\n",
      "dtypes: float64(2), int64(2), object(1)\n",
      "memory usage: 210.0+ KB\n"
     ]
    }
   ],
   "source": [
    "df.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [],
   "source": [
    "df['volume']=df['volume'].astype('int64')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [],
   "source": [
    "grpby = df.groupby('type')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<pandas.core.groupby.groupby.DataFrameGroupBy object at 0x7f37b7d66f60>"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "grpby"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [],
   "source": [
    "vol_type = grpby['volume'].sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "74466"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "vol_type['中性盘']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pymongo"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [],
   "source": [
    "db=pymongo.MongoClient('10.18.6.46',27001)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [],
   "source": [
    "doc=db['db_stock']['123006']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [],
   "source": [
    "import json"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [],
   "source": [
    "js=json.loads(df.T.to_json()).values()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [],
   "source": [
    "for row in js:\n",
    "    row['time']=datetime.datetime.utcfromtimestamp(row['time']/1000)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<pymongo.results.InsertManyResult at 0x1c33d6b97c8>"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "doc.insert_many(js)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [],
   "source": [
    "code='110030'\n",
    "doc = db['cb_deal'][code]\n",
    "d=[]\n",
    "for item in doc.find({},{'_id':0}):\n",
    "    d.append(item)\n",
    "df = pd.DataFrame(d)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>amount</th>\n",
       "      <th>change</th>\n",
       "      <th>code</th>\n",
       "      <th>price</th>\n",
       "      <th>time</th>\n",
       "      <th>type</th>\n",
       "      <th>volume</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1087</td>\n",
       "      <td>0.00</td>\n",
       "      <td>110030</td>\n",
       "      <td>108.66</td>\n",
       "      <td>2019-04-03 09:30:08</td>\n",
       "      <td>卖盘</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>76062</td>\n",
       "      <td>0.00</td>\n",
       "      <td>110030</td>\n",
       "      <td>108.66</td>\n",
       "      <td>2019-04-03 09:30:11</td>\n",
       "      <td>买盘</td>\n",
       "      <td>70</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>10866</td>\n",
       "      <td>0.00</td>\n",
       "      <td>110030</td>\n",
       "      <td>108.66</td>\n",
       "      <td>2019-04-03 09:30:17</td>\n",
       "      <td>买盘</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>10851</td>\n",
       "      <td>-0.15</td>\n",
       "      <td>110030</td>\n",
       "      <td>108.51</td>\n",
       "      <td>2019-04-03 09:30:59</td>\n",
       "      <td>卖盘</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>20617</td>\n",
       "      <td>0.00</td>\n",
       "      <td>110030</td>\n",
       "      <td>108.51</td>\n",
       "      <td>2019-04-03 09:32:05</td>\n",
       "      <td>卖盘</td>\n",
       "      <td>19</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   amount  change    code   price                time type  volume\n",
       "0    1087    0.00  110030  108.66 2019-04-03 09:30:08   卖盘       1\n",
       "1   76062    0.00  110030  108.66 2019-04-03 09:30:11   买盘      70\n",
       "2   10866    0.00  110030  108.66 2019-04-03 09:30:17   买盘      10\n",
       "3   10851   -0.15  110030  108.51 2019-04-03 09:30:59   卖盘      10\n",
       "4   20617    0.00  110030  108.51 2019-04-03 09:32:05   卖盘      19"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [],
   "source": [
    "df=df.set_index('time',drop=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>amount</th>\n",
       "      <th>change</th>\n",
       "      <th>code</th>\n",
       "      <th>price</th>\n",
       "      <th>type</th>\n",
       "      <th>volume</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>time</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-04-03 09:30:08</th>\n",
       "      <td>1087</td>\n",
       "      <td>0.00</td>\n",
       "      <td>110030</td>\n",
       "      <td>108.66</td>\n",
       "      <td>卖盘</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-04-03 09:30:11</th>\n",
       "      <td>76062</td>\n",
       "      <td>0.00</td>\n",
       "      <td>110030</td>\n",
       "      <td>108.66</td>\n",
       "      <td>买盘</td>\n",
       "      <td>70</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-04-03 09:30:17</th>\n",
       "      <td>10866</td>\n",
       "      <td>0.00</td>\n",
       "      <td>110030</td>\n",
       "      <td>108.66</td>\n",
       "      <td>买盘</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-04-03 09:30:59</th>\n",
       "      <td>10851</td>\n",
       "      <td>-0.15</td>\n",
       "      <td>110030</td>\n",
       "      <td>108.51</td>\n",
       "      <td>卖盘</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-04-03 09:32:05</th>\n",
       "      <td>20617</td>\n",
       "      <td>0.00</td>\n",
       "      <td>110030</td>\n",
       "      <td>108.51</td>\n",
       "      <td>卖盘</td>\n",
       "      <td>19</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                     amount  change    code   price type  volume\n",
       "time                                                            \n",
       "2019-04-03 09:30:08    1087    0.00  110030  108.66   卖盘       1\n",
       "2019-04-03 09:30:11   76062    0.00  110030  108.66   买盘      70\n",
       "2019-04-03 09:30:17   10866    0.00  110030  108.66   买盘      10\n",
       "2019-04-03 09:30:59   10851   -0.15  110030  108.51   卖盘      10\n",
       "2019-04-03 09:32:05   20617    0.00  110030  108.51   卖盘      19"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [],
   "source": [
    "slice_df = df['2019-04-03']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>amount</th>\n",
       "      <th>change</th>\n",
       "      <th>code</th>\n",
       "      <th>price</th>\n",
       "      <th>type</th>\n",
       "      <th>volume</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>time</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-04-03 11:25:59</th>\n",
       "      <td>545660</td>\n",
       "      <td>-0.13</td>\n",
       "      <td>110030</td>\n",
       "      <td>109.13</td>\n",
       "      <td>卖盘</td>\n",
       "      <td>500</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-04-03 13:40:27</th>\n",
       "      <td>459634</td>\n",
       "      <td>0.01</td>\n",
       "      <td>110030</td>\n",
       "      <td>108.92</td>\n",
       "      <td>买盘</td>\n",
       "      <td>422</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-04-03 14:30:23</th>\n",
       "      <td>653980</td>\n",
       "      <td>0.10</td>\n",
       "      <td>110030</td>\n",
       "      <td>109.00</td>\n",
       "      <td>买盘</td>\n",
       "      <td>600</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                     amount  change    code   price type  volume\n",
       "time                                                            \n",
       "2019-04-03 11:25:59  545660   -0.13  110030  109.13   卖盘     500\n",
       "2019-04-03 13:40:27  459634    0.01  110030  108.92   买盘     422\n",
       "2019-04-03 14:30:23  653980    0.10  110030  109.00   买盘     600"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "slice_df[slice_df['volume']>400]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [],
   "source": [
    "t=slice_df.resample('min').sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 1张1000元\n",
    "# 100张 10w块\n",
    "# 10000张 100w\n",
    "t[t['volume']>1000]['volume'].count()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
